<?php
require 'Model.php';
class IndexModel extends Model{

function getvideo1(){
	$sql="select * from videos where tid=1 limit 6";
	$data1=$this->conn->query($sql);
	return $data1;
}
function getvideo2(){
	$sql="select * from videos where tid=2 limit 6";
	$data2=$this->conn->query($sql);
	return $data2;
}
function getvideo3(){
	$sql="select * from videos where tid=3 limit 6";
	$data3=$this->conn->query($sql);
	return $data3;
}
function getvideo4(){
	$sql="select * from videos where tid=9 limit 6";
	$data4=$this->conn->query($sql);
	return $data4;
}
function adduser($data,$file){
//文件上传
$arr=explode('.', $file['pic']['name']);
$suffix=$arr[count($arr)-1];
$newname=date("YmdHis").rand(100,999).'.'.$suffix;
$filepath='./photos/';
	
move_uploaded_file($file['pic']['tmp_name'], $filepath.$newname);
//把数据插入数据库
$uname=$data['username'];
$password=$data['password'];
$gender=$data['gender'];
$birthdate=$data['birthdate'];
$hobby=implode($data['hobby'], ',');
$degree=$data['degree'];
$intro=$data['intro'];
$pic=$newname;
$sql="insert into users values(null,'$uname',md5('$password'),$gender,'$birthdate','$hobby',$degree,'$intro','$pic')";
$result=$this->conn->query($sql);
	return $result;
}
function listall($tid){
$sql="select * from videos where tid=$tid";
	$data=$this->conn->query($sql);
	return $data;
}
function show($vid){
$sql="select * from videos where vid=$vid";
	$data=$this->conn->query($sql);
	return $data;	
}

function dologin($data){
	$username=$data['username'];
	$password=$data['password'];
	$sql="select * from users where uname='$username' and password=md5('$password')";
	echo $sql;
	$result=$this->conn->query($sql);
	return $result;

}
}
 ?>
